package com.jzo2o.market.controller.operation;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.market.model.dto.request.ActivityQueryForPageReqDTO;
import com.jzo2o.market.model.dto.request.ActivitySaveReqDTO;
import com.jzo2o.market.model.dto.response.ActivityInfoResDTO;
import com.jzo2o.market.service.IActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description ActicityController
 * @Author CoreryBlack
 * @Date 2024-12-15
 */

@RestController("acticityController")
@Api(tags = "优惠券活动管理")
@RequestMapping("/operation/activity")
public class ActicityController {

    @Autowired
    private IActivityService activityService;

    @PostMapping("/save")
    @ApiOperation("保存优惠券")
    public void save(@RequestBody ActivitySaveReqDTO activitySaveReqDTO) {
        activityService.save(activitySaveReqDTO);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询优惠券")
    public PageResult<ActivityInfoResDTO> pageQuery(ActivityQueryForPageReqDTO activityQueryForPageReqDTO) {
        return activityService.pageQuery(activityQueryForPageReqDTO);
    }

    @GetMapping("/{id}")
    @ApiOperation("查询优惠券活动详情")
    public ActivityInfoResDTO getInfoById(@PathVariable Long id) {
        return activityService.getInfoById(id);
    }

    @PostMapping("/revoke/{id}")
    @ApiOperation("撤销活动")
    public void revoke(@PathVariable Long id){
        activityService.revoke(id);
    }

    @GetMapping("/list")
    @ApiOperation("用户端抢券列表分页接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tabType", value = "页面tab类型，1：疯抢中，2：即将开始", required = true, dataTypeClass = Integer.class)})
    public List<ActivityInfoResDTO> queryForPage(@RequestParam(value = "tabType",required = true) Integer tabType) {
        return activityService.queryActivityList(tabType);
    }
}
